package com.itheima.vmmysql.Service.Impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.springframework.stereotype.Service;

import com.itheima.vmmysql.Config.DataBaseConfig;
import com.itheima.vmmysql.Service.DataBaseTestService;
@Service
public class DataBaseTestServiceImpl implements DataBaseTestService {
    @Override
    public boolean testConnection(DataBaseConfig config) {
        String url = "jdbc:mysql://" + config.getAddress();
        String username = config.getUsername();
        String password = config.getPassword();

        try (Connection connection = DriverManager.getConnection(url, username, password)) {
            return connection != null && !connection.isClosed();
        } catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }
}
